﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rbac.Contracts.DTO.InPut;
using Rbac.Contracts.DTO.OutPut;
using Rbac.Contracts.Interface;

namespace Rbac.API.Controllers
{
	/// <summary>
	/// 角色权限
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[Authorize]
	public class RolePermissionController : ControllerBase
	{
		private readonly IRolePermissionServer _rolePermissionServer;
		public RolePermissionController(IRolePermissionServer rolePermissionServer)
		{
			_rolePermissionServer = rolePermissionServer;
		}
		/// <summary>
		/// 为角色分配权限
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		public Results<int> DistributeRolePermissions([FromBody]DistributeRolePermissionsInput input)
		{
			return Results<int>.DataResult(_rolePermissionServer.DistributeRolePermissions(input));
		}
		/// <summary>
		/// 权限角色获取权限列表
		/// </summary>
		/// <param name="roleId"></param>
		/// <returns></returns>
		[HttpGet]
		public Results<List<PermissionDTO>> GetPermissionsByRoleId(int roleId)
		{
			return Results<List<PermissionDTO>>.DataResult(_rolePermissionServer.GetPermissionsByRoleId(roleId));
		}
	}
}
